package com.example.springbootdemo.controller;

import com.example.springbootdemo.entity.LayData;
import com.example.springbootdemo.entity.User;
import com.example.springbootdemo.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("user")
public class UserController {
    @Resource
    private UserService userService;

    /**
     * 查询所有的用户
     * @return
     */
    @GetMapping("getUser")
    @ResponseBody
    public LayData getAllUser(){
        List<User> user = userService.getUser();
        return new LayData(user);
    }

    /**
     * 添加用户
     */
    @PostMapping("adduser")
    @ResponseBody
    public LayData addUser(User user){
        Boolean isno = userService.addOneUSer(user);
        return new LayData(isno);
    }
}
